import { request } from '@umijs/max';

import * as Storage from '@/services/storage';

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  return request<Promise<API.LoginResult>>('/icloud/admin/user/login', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

export async function logout(options?: { [key: string]: any}){
  return request<Promise<void>>('/icloud/admin/user/logout', {
    method: 'POST',
    data: 'logout',
    ...(options || {}),
  }).finally(()=>{
    Storage.clear();
  })
}

export async function listUser(
  {current=1, pageSize=10} : {keyword?:string, current?:number, pageSize?:number}={},
  options?:{[key:string]:any}){
  return request<Promise<API.Result>>('/icloud/admin/user/list', {
    method: 'GET',
    params: {current, pageSize},
    ...(options || {}),
  });
}